# 扫描项目根目录
function(SerchRoot addr notSerch)
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") 
        EXECUTE_PROCESS(COMMAND ls
        TIMEOUT 5
        OUTPUT_VARIABLE ROOT_DIR_LIST
        OUTPUT_STRIP_TRAILING_WHITESPACE
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
    elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
        EXECUTE_PROCESS(COMMAND powershell ls -Name -Exclude *.*
        TIMEOUT 5
        OUTPUT_VARIABLE ROOT_DIR_LIST
        OUTPUT_STRIP_TRAILING_WHITESPACE
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
    endif()
    foreach(Item ${${notSerch}})
        string(REGEX REPLACE "${Item}\n" "" ROOT_DIR_LIST ${ROOT_DIR_LIST})
    endforeach()
    string(REGEX REPLACE "\n" ";" ROOT_DIR_LIST ${ROOT_DIR_LIST})
    set(${addr} ${ROOT_DIR_LIST} PARENT_SCOPE)
endfunction()

# 搜索指定路径的头文件目录
function(SerchIncDir result curPath)
    file(GLOB_RECURSE FileLists ${${curPath}})
    set(IncLists "")
    set(LastDir "")
    foreach(incPath ${FileLists})
        string(REGEX REPLACE "(.*)/.*\.h.*" "\\1" Temp ${incPath})
        string(COMPARE EQUAL "${Temp}" "${LastDir}" isTrue)
        if((NOT isTrue) AND IS_DIRECTORY ${Temp})
                LIST(APPEND IncLists ${Temp})
        endif()
        set(LastDir ${Temp})
    endforeach()
    set(${result} ${IncLists} PARENT_SCOPE)
endfunction()
# 搜索指定目录的头文件目录 和 C/C++源文件
macro(SourceIncAndSrc SrcResult IncResult FullPath)
    set(SrcLists "")
    set(sIncLists "")
    foreach(Item ${${FullPath}})
        string(REGEX REPLACE "(.+)" "\\1/*.[cCsS]*" SrcItem ${Item})
        LIST(APPEND SrcLists ${SrcItem})
        string(REGEX REPLACE "(.+)" "\\1/*.h*" IncItem ${Item})
        LIST(APPEND sIncLists ${IncItem})
    endforeach()
    file(GLOB_RECURSE SOURCES ${SrcLists})
    SerchIncDir(INCLUDE sIncLists)
    set(${SrcResult} ${SOURCES})
    set(${IncResult} ${INCLUDE})
endmacro()